package com.zoagroup.funzy.entity;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;


/**
 * The persistent class for the ranking database table.
 * 
 */
@Entity
public class Ranking implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="id_ranking")
	private int idRanking;

	private String type;

	//bi-directional one-to-one association to Activity
	@OneToOne
	@JoinColumn(name="id_activity")
	private Activity activity;

	//bi-directional many-to-one association to RankingGroup
	@OneToMany(mappedBy="ranking", cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	private List<RankingGroup> rankingGroups;

	//bi-directional many-to-one association to RankingUser
	@OneToMany(mappedBy="ranking", cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	private List<RankingUser> rankingUsers;

	public Ranking() {
	}

	public int getIdRanking() {
		return this.idRanking;
	}

	public void setIdRanking(int idRanking) {
		this.idRanking = idRanking;
	}

	public String getType() {
		return this.type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Activity getActivity() {
		return this.activity;
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}

	public List<RankingGroup> getRankingGroups() {
		return this.rankingGroups;
	}

	public void setRankingGroups(List<RankingGroup> rankingGroups) {
		this.rankingGroups = rankingGroups;
	}

	public RankingGroup addRankingGroup(RankingGroup rankingGroup) {
		if(rankingGroups == null) {
			rankingGroups = new LinkedList<RankingGroup>();
		}
		getRankingGroups().add(rankingGroup);
		rankingGroup.setRanking(this);

		return rankingGroup;
	}

	public RankingGroup removeRankingGroup(RankingGroup rankingGroup) {
		if(rankingGroups == null) {
			rankingGroups = new LinkedList<RankingGroup>();
		}
		getRankingGroups().remove(rankingGroup);
		rankingGroup.setRanking(null);

		return rankingGroup;
	}

	public List<RankingUser> getRankingUsers() {
		return this.rankingUsers;
	}

	public void setRankingUsers(List<RankingUser> rankingUsers) {
		this.rankingUsers = rankingUsers;
	}

	public RankingUser addRankingUser(RankingUser rankingUser) {
		if(rankingUsers == null) {
			rankingUsers = new LinkedList<RankingUser>();
		}			
		getRankingUsers().add(rankingUser);
		rankingUser.setRanking(this);

		return rankingUser;
	}

	public RankingUser removeRankingUser(RankingUser rankingUser) {
		if(rankingUsers == null) {
			rankingUsers = new LinkedList<RankingUser>();
		}	
		getRankingUsers().remove(rankingUser);
		rankingUser.setRanking(null);

		return rankingUser;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + idRanking;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Ranking other = (Ranking) obj;
		if (idRanking != other.idRanking)
			return false;
		return true;
	}
}